package com.bodu.system.service.impl;

import com.bodu.core.entity.ParamReq;
import com.bodu.system.entity.po.RolePo;
import com.bodu.system.entity.request.RoleRequest;
import com.bodu.system.entity.vo.RoleVo;
import com.bodu.system.mapper.RoleMapper;
import com.bodu.system.service.RoleService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author r.guo
 * @since 2019-05-25
 */
@Service("roleService")
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public RoleVo getModel(Long id) {
        RolePo rolePo = roleMapper.getModel(id);
        RoleVo roleVo = new RoleVo();
        BeanUtils.copyProperties(rolePo, roleVo);
        return roleVo;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Long save(RoleRequest role) {
        roleMapper.save(role);
        return role.getId();
    }

    @Override
    public Long update(RoleRequest request) {
        roleMapper.update(request);
        return request.getId();
    }

    @Override
    public List<RoleVo> listPage(ParamReq<RoleRequest> params) {
        return roleMapper.listPage(params);
    }

    @Override
    public Integer countPage(ParamReq<RoleRequest> params) {
        return roleMapper.countPage(params);
    }


    @Override
    public Integer updateDelFlagById(Long id, Integer delFlag) {
        return roleMapper.updateDelFlagById(id, delFlag);
    }

    @Override
    public List<RolePo> listByAdminId(Long id) {
        return roleMapper.listByAdminId(id);
    }
}
